package EventManager;

/**
 * An abstract Administrator request. Most admin functions are of this type and won't be processed unless are 
 * issued by an admin.
 * 
 * @author Yury Kitaev
 *
 */
public abstract class AdminRequest extends Request
{

	private Administrator issuer;


	/**
	 * Constructor.
	 * @param issuer The administrator who issues the request.
	 */
	public AdminRequest (Administrator issuer)
	{
		super();
		setIssuer(issuer);
	}
	
	/**
	 * Only an administrator can issue Admin requests. This method shall be overridden, but it is useful to call it from the subclass to do null checks and other (potentially) useful things.
	 * @param issuer The pointer to the Administrator who issues the request.
	 */
	public void process (Administrator issuer)
	{
		if (null == issuer)
		{
			throw new NullPointerException("The issuer of the admin request must be identified!");
		}
	}
	
	@Override
	public final void process()
	{
		// Refuse requests by non-administrators
		setStatus(RequestStatus.Refused);
	}
	
	@Override
	public String toString() 
	{
		return this.getClass().toString() +  " issued by " + issuer + "; status = " + getStatus().toString().toUpperCase();
	}

	public Administrator getIssuer() 
	{
		return issuer;
	}

	public void setIssuer(Administrator issuer) 
	{
		this.issuer = issuer;
	}
}
